# -*- coding: utf-8 -*-

from method import *
import threading,time
# write_yaml(r"D:\python\pythonProject\test\add_employee_requests.yaml",data1)
# write_yaml(r"D:\python\pythonProject\test\add_employee_requests.yaml",data_uat1)

write_yaml(r"D:\python\pythonProject\test\requests.yaml",oa_data_154)

def login():
    #登录接口
    url = read_yaml(0, '登录')['url']
    headers = read_yaml(0, '登录')['headers']
    data = read_yaml(0, '登录')['data']
    ree = send_requests(0, '登录', url, data, headers)
    a1 = json.loads(ree.text)
    token = a1['data']['token']
    return token


def pendingPage():
    start_time = time.time()  # 记录开始时间
    # 调用列表接口，获取列表中三个字段的数据
    url = read_yaml(1,'待处理页面')['url']
    headers = read_yaml(1,'待处理页面')['headers']
    headers['Authorization']=login()
    data = read_yaml(1,'待处理页面')['data']
    ree = send_requests(1, '待处理页面', url, data, headers)
    a = json.loads(ree.text)
    list_all = a['data']['records']
    #流程名称列表
    list1 = []
    #流程发起人列表
    list2 = []
    #机构简称列表
    list3 = []
    for i in list_all:
        list1.append(i['auditConfigName'])
        list2.append(i['applyName'])
        if i['clientName'] is not None:
            list3.append(i['clientName'])

    # 处理机构简称列表数据
    original_list = list(set(list3))
    unique_list=deal_list(original_list)
    #调用下拉框接口，获取下拉框选项数据
    url1 = read_yaml(2, '待处理页面下拉框')['url']
    headers1 = read_yaml(2, '待处理页面下拉框')['headers']
    headers1['Authorization'] = login()
    data1 = read_yaml(2, '待处理页面下拉框')['data']
    ree1 = send_requests(2, '待处理页面下拉框', url1, data1, headers1)
    a1 = json.loads(ree1.text)
    # 流程名称下拉框列表
    list_auditConfigName = []
    # 流程发起人下拉框列表
    list_applyName = []
    # 机构简称下拉框列表
    list_examineContractName=[]

    for i in a1['data']['applyName']:
        list_applyName.append(i['label'])
    for i in a1['data']['auditConfigName']:
        list_auditConfigName.append(i['label'])
    for i in a1['data']['examineContractName']:
        list_examineContractName.append(i['label'])

    #判断流程名称结果是否一致
    unique(list1,list_auditConfigName)

    # 判断流程发起人结果是否一致
    unique(list2, list_applyName)

    # 判断机构简称结果是否一致
    unique(unique_list,list_examineContractName)

    print("待处理页面流程名称有" + str(len(set(list1))) + '个 ：' + str(set(list1)))
    print("待处理页面流程发起人有" + str(len(set(list2))) + '个 ：' + str(set(list2)))
    print("待处理页面机构简称有" + str(len(unique_list)) + '个 ：' + str(unique_list))
    end_time = time.time()  # 记录结束时间
    run_time = end_time - start_time  # 计算运行时间（单位为秒）
    print("脚本运行时间：", round(run_time, 2), '秒')
    print("--------------------------------------end-------------------------------")

def processedpage():
    start_time = time.time()  # 记录开始时间
    # 调用列表接口，获取列表中三个字段的数据
    url = read_yaml(3, '已处理页面')['url']
    headers = read_yaml(3, '已处理页面')['headers']
    headers['Authorization'] = login()
    data = read_yaml(3, '已处理页面')['data']
    ree = send_requests(3, '已处理页面', url, data, headers)
    a = json.loads(ree.text)
    list_all = a['data']['records']
    #流程名称列表
    list1 = []
    #流程发起人列表
    list2 = []
    #机构简称列表
    list3 = []
    for i in list_all:
        list1.append(i['auditConfigName'])
        list2.append(i['applyName'])
        if i['clientName'] is not None:
            list3.append(i['clientName'])

    # 处理机构简称列表数据
    original_list = list(set(list3))
    unique_list = deal_list(original_list)
    # 调用下拉框接口，获取下拉框选项数据
    url1 = read_yaml(4, '已处理页面下拉框')['url']
    headers1 = read_yaml(4, '已处理页面下拉框')['headers']
    headers1['Authorization'] = login()
    data1 = read_yaml(4, '已处理页面下拉框')['data']
    ree1 = send_requests(4, '已处理页面下拉框', url1, data1, headers1)
    a1 = json.loads(ree1.text)

    # 流程名称下拉框列表
    list_auditConfigName = []
    # 流程发起人下拉框列表
    list_applyName = []
    # 机构简称下拉框列表
    list_examineContractName=[]

    for i in a1['data']['applyName']:
        list_applyName.append(i['label'])
    for i in a1['data']['auditConfigName']:
        list_auditConfigName.append(i['label'])
    for i in a1['data']['examineContractName']:
        list_examineContractName.append(i['label'])

    # 判断流程名称结果是否一致
    unique(list1, list_auditConfigName)

    # 判断流程发起人结果是否一致
    unique(list2, list_applyName)

    # 判断机构简称结果是否一致
    unique(unique_list, list_examineContractName)

    print("已处理页面流程名称有" + str(len(set(list1))) + '个 ：' + str(set(list1)))
    print("已处理页面流程发起人有" + str(len(set(list2))) + '个 ：' + str(set(list2)))
    print("已处理页面机构简称有" + str(len(unique_list)) + '个 ：' + str(unique_list))
    end_time = time.time()  # 记录结束时间
    run_time = end_time - start_time  # 计算运行时间（单位为秒）
    print("脚本运行时间：", round(run_time, 2), '秒')
    print("--------------------------------------end-------------------------------")


def ccmypage():
    start_time = time.time()  # 记录开始时间
    # 调用列表接口，获取列表中三个字段的数据
    url = read_yaml(5, '抄送我页面')['url']
    headers = read_yaml(5, '抄送我页面')['headers']
    headers['Authorization'] = login()
    data = read_yaml(5, '抄送我页面')['data']
    ree = send_requests(5, '抄送我页面', url, data, headers)
    a = json.loads(ree.text)
    list_all = a['data']['records']
    #流程名称列表
    list1 = []
    #流程发起人列表
    list2 = []
    #机构简称列表
    list3 = []
    for i in list_all:
        list1.append(i['auditConfigName'])
        list2.append(i['applyName'])
        if i['clientName'] is not None:
            list3.append(i['clientName'])

    # 处理机构简称列表数据
    original_list = list(set(list3))
    unique_list = deal_list(original_list)
    # 调用下拉框接口，获取下拉框选项数据
    url1 = read_yaml(6, '抄送我页面下拉框')['url']
    headers1 = read_yaml(6, '抄送我页面下拉框')['headers']
    headers1['Authorization'] = login()
    data1 = read_yaml(6, '抄送我页面下拉框')['data']
    ree1 = send_requests(6, '抄送我页面下拉框', url1, data1, headers1)
    a1 = json.loads(ree1.text)

    # 流程名称下拉框列表
    list_auditConfigName = []
    # 流程发起人下拉框列表
    list_applyName = []
    # 机构简称下拉框列表
    list_examineContractName=[]

    for i in a1['data']['applyName']:
        list_applyName.append(i['label'])
    for i in a1['data']['auditConfigName']:
        list_auditConfigName.append(i['label'])
    for i in a1['data']['examineContractName']:
        list_examineContractName.append(i['label'])

    # 判断流程名称结果是否一致
    unique(list1, list_auditConfigName)

    # 判断流程发起人结果是否一致
    unique(list2, list_applyName)

    # 判断机构简称结果是否一致
    unique(unique_list, list_examineContractName)

    print("抄送我页面流程名称有" + str(len(set(list1))) + '个 ：' + str(set(list1)))
    print("抄送我页面流程发起人有" + str(len(set(list2))) + '个 ：' + str(set(list2)))
    print("抄送我页面机构简称有" + str(len(unique_list)) + '个 ：' + str(unique_list))
    end_time = time.time()  # 记录结束时间
    run_time = end_time - start_time  # 计算运行时间（单位为秒）
    print("脚本运行时间：", round(run_time, 2), '秒')
    print("--------------------------------------end-------------------------------")


def pageinitiated():
    start_time = time.time()  # 记录开始时间
    # 调用列表接口，获取列表中三个字段的数据
    url = read_yaml(7, '已发起页面')['url']
    headers = read_yaml(7, '已发起页面')['headers']
    headers['Authorization'] = login()
    data = read_yaml(7, '已发起页面')['data']
    ree = send_requests(7, '已发起页面', url, data, headers)
    a = json.loads(ree.text)
    list_all = a['data']['records']
    #流程名称列表
    list1 = []
    #流程发起人列表
    list2 = []
    #机构简称列表
    list3 = []
    for i in list_all:
        list1.append(i['auditConfigName'])
        list2.append(i['applyName'])
        if i['clientName'] is not None:
            list3.append(i['clientName'])

    # 处理机构简称列表数据
    original_list = list(set(list3))
    unique_list = deal_list(original_list)
    # 调用下拉框接口，获取下拉框选项数据
    url1 = read_yaml(8, '已发起页面下拉框')['url']
    headers1 = read_yaml(8, '已发起页面下拉框')['headers']
    headers1['Authorization'] = login()
    data1 = read_yaml(8, '已发起页面下拉框')['data']
    ree1 = send_requests(8, '已发起页面下拉框', url1, data1, headers1)
    a1 = json.loads(ree1.text)

    # 流程名称下拉框列表
    list_auditConfigName = []
    # 流程发起人下拉框列表
    list_applyName = []
    # 机构简称下拉框列表
    list_examineContractName=[]

    for i in a1['data']['applyName']:
        list_applyName.append(i['label'])
    for i in a1['data']['auditConfigName']:
        list_auditConfigName.append(i['label'])
    for i in a1['data']['examineContractName']:
        list_examineContractName.append(i['label'])

    # 判断流程名称结果是否一致
    unique(list1, list_auditConfigName)

    # 判断流程发起人结果是否一致
    unique(list2, list_applyName)

    # 判断机构简称结果是否一致
    unique(unique_list, list_examineContractName)

    print("已发起页面流程名称有" + str(len(set(list1))) + '个 ：' + str(set(list1)))
    print("已发起页面流程发起人有" + str(len(set(list2))) + '个 ：' + str(set(list2)))
    print("已发起页面机构简称有" + str(len(unique_list)) + '个 ：' + str(unique_list))
    end_time = time.time()  # 记录结束时间
    run_time = end_time - start_time  # 计算运行时间（单位为秒）
    print("脚本运行时间：", round(run_time, 2), '秒')
    print("--------------------------------------end-------------------------------")


def allpages():
    start_time = time.time()  # 记录开始时间
    # 调用列表接口，获取列表中三个字段的数据
    url = read_yaml(9, '全部流程页面')['url']
    headers = read_yaml(9, '全部流程页面')['headers']
    headers['Authorization'] = login()
    data = read_yaml(9, '全部流程页面')['data']
    ree = send_requests(9, '全部流程页面', url, data, headers)
    a = json.loads(ree.text)
    list_all = a['data']['records']
    #流程名称列表
    list1 = []
    #流程发起人列表
    list2 = []
    #机构简称列表
    list3 = []
    for i in list_all:
        list1.append(i['auditConfigName'])
        list2.append(i['applyName'])
        if i['clientName'] is not None:
            list3.append(i['clientName'])

    # 处理机构简称列表数据
    original_list = list(set(list3))
    unique_list = deal_list(original_list)
    # 调用下拉框接口，获取下拉框选项数据
    url1 = read_yaml(10, '全部流程页面下拉框')['url']
    headers1 = read_yaml(10, '全部流程页面下拉框')['headers']
    headers1['Authorization'] = login()
    data1 = read_yaml(10, '全部流程页面下拉框')['data']
    ree1 = send_requests(10, '全部流程页面下拉框', url1, data1, headers1)
    a1 = json.loads(ree1.text)

    # 流程名称下拉框列表
    list_auditConfigName = []
    # 流程发起人下拉框列表
    list_applyName = []
    # 机构简称下拉框列表
    list_examineContractName=[]

    for i in a1['data']['applyName']:
        list_applyName.append(i['label'])
    for i in a1['data']['auditConfigName']:
        list_auditConfigName.append(i['label'])
    for i in a1['data']['examineContractName']:
        list_examineContractName.append(i['label'])

    # 判断流程名称结果是否一致
    unique(list1, list_auditConfigName)

    # 判断流程发起人结果是否一致
    unique(list2, list_applyName)

    # 判断机构简称结果是否一致
    unique(unique_list, list_examineContractName)

    print("全部流程页面流程名称有" + str(len(set(list1))) + '个 ：' + str(set(list1)))
    print("全部流程页面流程发起人有" + str(len(set(list2))) + '个 ：' + str(set(list2)))
    print("全部流程页面机构简称有" + str(len(unique_list)) + '个 ：' + str(unique_list))
    end_time = time.time()  # 记录结束时间
    run_time = end_time - start_time  # 计算运行时间（单位为秒）
    print("脚本运行时间：", round(run_time, 2), '秒')
    print("--------------------------------------end-------------------------------")

# 创建线程对象
thread1 = threading.Thread(target=pendingPage)
thread2 = threading.Thread(target=processedpage)
thread3 = threading.Thread(target=ccmypage)
thread4 = threading.Thread(target=pageinitiated)
thread5 = threading.Thread(target=allpages)

#启动线程
thread1.start()
thread2.start()
thread3.start()
thread4.start()
thread5.start()
# 等待线程执行完成
thread1.join()
thread2.join()
thread3.join()
thread4.join()
thread5.join()

print("All threads have finished executing")